define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'room_check/index' + location.search,
                    add_url: 'room_check/add',
                    edit_url: 'room_check/edit',
                    del_url: 'room_check/del',
                    multi_url: 'room_check/multi',
                    table: 'room_check',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'typedata', title: __('Typedata'), searchList: {"1":__('Typedata 1'),"2":__('Typedata 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'user.username', title: __('User.username')},
                        {field: 'site.sitename', title: __('Site.sitename')},
                        {field: 'province_id',visible: false, title: __('Province_id')},
                        {field: 'city_id',visible: false, title: __('City_id')},
                        {field: 'county_id',visible: false, title: __('County_id')},
                        {field: 'town_id',visible: false, title: __('Town_id')},
                        {field: 'site_id',visible: false, title: __('Site_id')},
                        {field: 'area_str', title: __('Area_str')},
                        {field: 'card_number', title: __('Card_number')},
                        {field: 'cardzimage', title: __('Cardzimage'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'cardfimage', title: __('Cardfimage'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'room_number', title: __('Room_number')},
                        {field: 'room_info', title: __('Room_info'),events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'checktime', title: __('Checktime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        { field: 'buttons',
                            width: "120px",
                            title: __('审核操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons:[{
                                name: 'ajax',
                                title: __('通过'),
                                classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                icon: 'fa fa-check',
                                url: 'room_check/check/status/1',
                                confirm: '审核通过？',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg);
                                    if(ret.code==1){
                                        $(".btn-refresh").trigger('click');
                                    }
                                    //如果需要阻止成功提示，则必须使用return false;
                                    return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },{
                                name: 'ajax',
                                title: __('不通过'),
                                classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                icon: 'fa fa-close',
                                url: 'room_check/check/status/2',
                                confirm: '审核不通过？',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg);
                                    if(ret.code==1){
                                        $(".btn-refresh").trigger('click');
                                    }
                                    //如果需要阻止成功提示，则必须使用return false;
                                    return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            }], formatter: Table.api.formatter.buttons},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});